package cn.admin.remoting.impl;

import cn.admin.remoting.Remoting;
import cn.admin.remoting.util.ReflectionUtil;
import org.apache.mina.common.ByteBuffer;

public class OnDeploy {

    private static int count = 0;

    public static synchronized void onDeploy() {

        if (count <= 0) {
            try {
                ReflectionUtil.setStaticField(Remoting.class,"sm",new DefaultServerManager());
                ReflectionUtil.setStaticField(Remoting.class,"spi",new SessionsFlushQueueServiceImpl());
            } catch (NoSuchFieldException | IllegalAccessException e) {
                throw new RuntimeException(e);
            }

            ByteBuffer.setUseDirectBuffers(false);
            ++ count;
        }

    }

}
